home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / EDITORS / ZAP130 / !Zap / Docs / E-Command < prev    next >
Text File  |  1995-06-19  |  22KB  |  552 lines

  1. *************************************************************************
  2. * >E-Command    Documents how to add commands to Zap            *
  3. *************************************************************************
  4.  
  5. As mentioned in the ReadMe file, commands are added to Zap by registering a
  6. table of commands when the module providing the extra commands initialises.
  7. You should use the call Zap_AddCommands to register the table. The table has
  8. the format below. All offsets are from your module start unless otherwise
  9. indicated.
  10.  
  11.     #0    Offset of table from start of module (so Zap can convert the
  12.         offsets below into addresses).
  13.     #4    Offset from module start of 'Zap service call code' or 0
  14.         if none. Zap calls this entry point to tell you about
  15.         various things - see the section below.
  16.     #8    List of commands, terminated by a zero word. Each element
  17.         of the list has the format:
  18.         
  19.         <command name>+<0 byte terminator>+
  20.         <ZERO bytes padding until word aligned>+
  21.         <word giving command offset from module start>
  22.         
  23. The command name must be in UPPER CASE in this table. In general, command
  24. names are not case sensitive, but they are converted to upper case in order
  25. to search for them in the command tables. The characters padding to the next
  26. word alignment MUST be ZEROs as the table is searched through in words not
  27. in bytes.
  28.  
  29. When a command is found in the table, its address is calculated, and
  30. henceforth the command is referred to by its address. This unfortunately
  31. means that I cannot pass the command your module workspace when the command
  32. is called as I do not know which module the command lies in. This is not
  33. usually a problem however as you may claim workspace from Zap's heap. If this
  34. is not sufficient, then you will just have to store the address of your
  35. workspace in the module itself and read it when you are called (until I work
  36. out a better method).
  37.  
  38. The address of the command is of course the address called when the command
  39. is executed. However, at offset -4, the word before the first instruction of
  40. the command, some flags are stored. These flags determine what type of
  41. parameter the command takes and how the command interacts with the
  42. minibuffer and menus. This word must be filled in. It's meaning is summarised
  43. below. Greater detail is given further down the file.
  44.  
  45. b0    Set if the command doesn't need R10 on entry (eg called from
  46. b1    Set if the command doesn't need R8 on entry   a menu).
  47. b2    Set if the command doesn't need R9 on entry
  48. b3-b5    Argument type for the command:
  49.     0 = Command takes no parameters
  50.     1 = Command takes a list of bytes as parameter
  51.     2 = Command takes a list of words as parameter
  52.     3 = Command takes a string as parameter
  53.     4 = Command takes a block of data as parameter
  54.     5-7 reserved
  55. b6    Set if you wished to be called before minibuffer opened
  56. b7    Set if you wish to be called after every minibuffer update
  57. b8    Set if you wish to be called before a key is inserted into
  58.     the minibuffer (and possibly alter it).
  59. b9    Set if you want TAB to complete file names in the minibuffer
  60. b10    Set if you may want to kill the minibuffer when it starts up.
  61. b11    Set if you may want minibuffer to remain open when command finished.
  62. b12    Set if Universal arg should multiply R1 by the number of times to do.
  63. b13    Set if command should be called repeatedly with R1 smaller.
  64. b14    Set if the command should not be executed when loading a file.
  65. b15    Set if the command is 'tickable' when on a menu entry.
  66. b16    Set if the command can create a submenu or leaf window.
  67. b17    Set if the command can provide a default string for a menu entry.
  68. b18    Set if the command wishes to provide the menu entry text.
  69. b19    Set if the command wishes to specify the submenu.
  70. b20    Set if the command may wish to remove the menu entry.
  71. b21-b31    Reserved - set to 0
  72.  
  73. The entry/exit conditions of your command depend on your flags word as I will
  74. detail below. When the command is called the registers have the meaning:
  75.  
  76.  R0 = input data for the command (dependent on R2 & command type - see below)
  77.  R1 = length of input data       (dependent on R2 & command type - see below)
  78.  R2 = action code         (details below)
  79.  
  80.  R8 = window of the input caret (see E-Windows) (unless flags b1 set)
  81.  R9 = file block associated with R8 (see E-File) (unless flags b2 set)
  82.  R10 = cursor block pointer of input cursor (see E-Cursors)
  83.        (unless flags b3 set) (This is car_cursor if the cursors are combined 
  84.        and car_input if they are split - see E-Vars).
  85.  R11 = undefined
  86.  R12 = Zap's workspace
  87.  R13 = small FD stack
  88.  
  89. ALL calls to your command have these registers set up. The descriptions of R0
  90. and R1 given above are for action code R2=0 (execute the command). In general
  91. their meaning will be dependent on R2 and are undefined otherwise. Note that
  92. you are only called with the action codes you request via your flags word so
  93. do not need to test for all possible action codes.
  94.     
  95. On exit from a command you may corrupt the registers R0-R11 and the flags.
  96. You should return V flag set and R0=error block on error. Some of the calls
  97. with R2<>0 require you to return a result in R0. To detail the actual meaning
  98. of R0-R2 I have partitioned into cases below. Registers not mentioned are
  99. undefined.
  100.  
  101. If you want to call a command yourself, then please use the call
  102. Zap_ProcessCommand or Zap_CommandString. All calls from Zap are made by this
  103. method. See the file 'Commands' for the syntax used when typing a command
  104. into the keys file, or sending it to Zap_CommandString.
  105.  
  106. NB Only command calls with R2=0 or R2=1 are learnt. All other calls are
  107. regarded as 'setup' calls and are not learnt.
  108.  
  109. ************************
  110. * Details of flag bits *
  111. ************************
  112.  
  113. Bit 0
  114. -----
  115.  
  116. If this bit is set then R10 is undefined on entry. If it is clear then the
  117. current position of the input cursor will be read if R10 is not specified (ie
  118. is 0) when Zap_ProcessCommand is called. Note that reading the current
  119. input cursor position may change R8 and R9 as well.
  120.  
  121. This is useful when the command is called from a menu. The menu may not be on
  122. the window with the input focus. If this bit is set then the command can act
  123. on the menu the window is on, where as if it is clear then it will always act
  124. on the window with the input focus. Thus it should be set for any command
  125. which only affects the window state and doesn't need to know the cursor
  126. position.
  127.  
  128. Bit 1
  129. -----
  130.  
  131. If this bit is set then R8 either points to a window or is 0 on entry. If 0
  132. then the command is being called from the options menu to change the default
  133. state. If the bit is clear and Zap_ProcessCommand is called with R8=0 then an
  134. error is given.
  135.  
  136. Thus this bit should be set for commands which don't need to know where the
  137. cursor is and can change the default options as well as the current window
  138. state. If this bit is set then you should also set Bit 0.
  139.  
  140. Bit 2
  141. -----
  142.  
  143. As for Bit 1 except that the file pointer R9 is checked instead of R8. If the
  144. command is called from the options menu then both R8 and R9 will be 0.
  145.  
  146. Bits 3-5
  147. --------
  148.  
  149. These determine what type of data the command takes. When the command is
  150. executed it is called with R2=0. In general the meaning of R2>0 is documented
  151. under the Bit with value R2. Note that Bits 12 and 13 are used in deciding
  152. which value is passed in R1. When the command is called with R2=0 additional
  153. information is passed in R3:
  154.  
  155.  R3 =     b0 Set => This command was executed as the last command as well.
  156.           (eg to spot cumulative ctrl K's/Yanks).
  157.     b1-b27 => Reserved
  158.     b28-b31=> Top bits of R2 when command called via Zap_ProcessCommand.
  159.  
  160.  Data type None (0) is called with:
  161.  
  162.   R0=undefined
  163.   R1=number of times the key has been pressed (depends on flags bits):
  164.      Suppose the key has been buffered a total of m times. Suppose also that
  165.      Universal argument (^U) is active and that the user has requested a
  166.      repetition of n times. (n=1 if universal argument not active).
  167.      Ie, Zap_ProcessCommand has been called with R1=m. Then:
  168.     b12=0 & b13=0 => Command is called n times with R1=m
  169.     b12=1 & b13=0 => Command is called once with R1=m*n
  170.     b12=0 & b13=1 => Command is called m*n times with R1=1
  171.     b12=1 & b13=1 => Command is called m times with R1=n
  172.     ie b12=1 => R1 is multiplied by n (the universal argument)
  173.        b13=1 => Called an extra m times with R1 divided by m.
  174.   R2=0 to execute the command.
  175.  
  176.  Data type Byte list (1):
  177.  
  178.   If the command takes a byte parameter, then when the keyboard input is
  179.   buffered, the bytes are buffered in a list as well. Hence the sequence
  180.   of keypresses: CHAR 65,CHAR 66,CHAR 67 will cause the command CHAR to be
  181.   called once with data list 65,66,67 (if b13=0).
  182.   
  183.   R0=pointer to a list of the bytes
  184.   R1=number of bytes in the list (depends on flag bits):
  185.      If m,n are as above (ie Zap_ProcessCommand has been called with R1=m,
  186.      R0 pointing to a list of m bytes, and universal command repeat=n) then:
  187.     b12=0 & b13=0 => Command is called n times with R1=m and the list of
  188.              bytes pointed to by R0 is m long.
  189.     b12=1 & b13=0 => Command is called once with R1=m*n and the list
  190.              of bytes pointed to by R0 is m*n long. Ie, the
  191.              list passed to Zap_ProcessCommand has been
  192.              duplicated n times.
  193.     b12=0 & b13=1 => Command is called m*n times with R1=1 and
  194.              R0 pointing to the single byte argument. (R0
  195.              incremented between command calls and wraps round).
  196.     b12=1 & b13=1 => Command is called m times with R1=n and R0 pointing
  197.              to the single byte argument. (R0 is incremented by
  198.              1 byte on each command call so it covers the list
  199.              of m bytes passed to Zap_ProcessCommand).
  200.   R2=0 to execute the command.
  201.  
  202.  Data type Word list (2):
  203.  
  204.   The details are the same as for Byte list typed data except that R0 points
  205.   to a list of words and R1 is the number of words (not bytes) in the list.
  206.  
  207.  Data type String (3) is called with:
  208.  
  209.   R0=pointer to the string (zero terminated)
  210.   R1=number of times key pressed (as for data type None above)
  211.   R2=0 if the string was specified (eg INSERT "Wibble")
  212.      1 if the string wasn't specified (eg INSERT) but has been typed into
  213.        the minibuffer (R0 points to the minibuffer contents in this case)
  214.        and then RETURN has been pressed.
  215.        
  216.   You can control the minibuffer, and the way the string is entered by using
  217.   bits 6-11 as documented below. Please set bit 6 and add a prompt where
  218.   possible. Your command should end up taking the same action regardless of
  219.   whether R2=0,1 for when learnt sequences are played back you are always
  220.   called with R2=0.
  221.   
  222.  Data type Block (4) is called with:
  223.  
  224.   R0=pointer to a data block (of command dependant format)
  225.   R1=number of times key pressed (as for data type None above)
  226.   R2=0 to execute the command.
  227.   
  228.   This is used by the command MULTICOMMAND which is used internally within
  229.   Zap to execute a compiled list of other commands. You cannot use this type
  230.   of command in the Keys file as there is no way to specify a parameter.
  231.   
  232. Bit 6
  233. -----
  234.  
  235. This bit is only used if the command takes a string parameter and it has not
  236. been supplied. The minibuffer is opened in this case and, if this bit is set,
  237. you are called to supply a prompt and add a default string after the prompt
  238. if you like. You are called with R2=6 (R0,R1 undefined). See also bit 10.
  239.  
  240. The minibuffer is cleared before you are called and opened on screen AFTER
  241. you return. Use Zap_MiniPrompt to add the prompt and Zap_MiniWrite to alter
  242. the contents of the rest of the minibuffer.
  243.  
  244. Bit 7
  245. -----
  246.  
  247. This bit is only used if the command takes a string parameter and the
  248. minibuffer has been opened. If this bit is set then you are called AFTER each
  249. key has been inserted into the minibuffer so you can examine its contents.
  250. You are called with:
  251.  
  252.  R0=pointer to minibuffer contents (after the prompt)
  253.  R1=undefined
  254.  R2=7
  255.  
  256. The minibuffer is updated on screen after you return.
  257.  
  258. Bit 8
  259. -----
  260.  
  261. This bit is only used if the command takes a string parameter and the
  262. minibuffer has been opened. If this bit is set then you are called BEFORE
  263. each key has been inserted into the minibuffer. You are called with:
  264.  
  265.  R0=pointer to minibuffer contents (after the prompt)
  266.  R1=undefined
  267.  R2=&8000+Zaps internal key number of the key about to be inserted into
  268.     the minibuffer.
  269.     
  270. and you should return:
  271.  
  272.  R0=-1 => leave the minibuffer unaltered - key not inserted (but you will
  273.        be called again if b7 is set).
  274.     0-&1FF => insert that key (Zap internal key number). Hence you will
  275.        usually exit via SUB R0,R2,#&8000. Returning &1B (Escape) will cause
  276.        the minibuffer to be closed.
  277.     &8000+key number => The minibuffer is quitted as if return had been
  278.        pressed (ie you are called with R2=1 etc) and the the indicated key
  279.        is acted on as if typed in the editing window.
  280.  
  281. You should use this call to trap insertions of TAB and make it act as a
  282. completion key. Filename completion can be done automatically - see b9.
  283.  
  284. Bit 9
  285. -----
  286.  
  287. If set then the TAB key automatically acts a 'filename completion' in the
  288. minibuffer.
  289.  
  290. Bit 10
  291. ------
  292.  
  293. This bit is only used if the command takes a string parameter and the
  294. minibuffer has been opened and bit 6 is also set. When you are called with
  295. R2=6 then if bit 10 is also set you should return with:
  296.  
  297.  R0=0 => continue as usual - ie open the minibuffer.
  298.     1 => total abort - you are opening your own window or something.
  299.     >1 => abort the minibuffer and execute the command as normal with R2=0
  300.            and with parameter the string pointed to by this R0.
  301.  
  302. NB Do not execute the command on this call - it will not be leant. This is
  303. why you should pass the argument back in R0.
  304.  
  305. Bit 11
  306. ------
  307.  
  308. This bit is only used if the command takes a string parameter and the
  309. minibuffer has been opened. When the user presses return the minibuffer is
  310. usually closed after you have been called with R2=1 to execute the command.
  311. If this bit is set then you can return a value in R0 (from being called with
  312. R2=1) to stop this:
  313.  
  314.  R0=0 => close the minibuffer as usual.
  315.     1 => leave the minibuffer open.
  316.  
  317. Bit 12-13
  318. ---------
  319.  
  320. These control the value of R1 when your command is called with R2=0. See Bits
  321. 3-5 for more details.
  322.  
  323. Bit 14
  324. ------
  325.  
  326. If set then the command is regarded as 'unsafe'. Ie, it could possibly be
  327. used in a Trojan an should not be executed automatically on the loading of a
  328. text file by specifying it in the first few lines of the file. The OSCLI
  329. command is a good example of this.
  330.  
  331. Bit 15
  332. ------
  333.  
  334. This bit is only used if the command is used on a menu entry. If set then
  335. you are asked whether the menu item should be ticked or shaded. You are
  336. called when the menu entry is opened with:
  337.  
  338.  R0=command data (pointer to byte/word/string)
  339.  R2=15
  340.  R10 need not be valid even if b1 is clear (R10=0 if not valid)
  341.  
  342.  and you should return
  343.  
  344.  R0 = b0 set => menu item should be ticked
  345.       b1 set => menu item should be shaded
  346.       b2+ reserved - set to 0
  347.  
  348. Bit 16
  349. ------
  350.  
  351. This bit is only used if the command is used on a menu entry. If set then it
  352. indicates that the command can be used as a submenu pointer. The submenu
  353. warning bit is set and when the user tries to open the submenu you are called
  354. with R2=16 and should return:
  355.  
  356.  R0 = window handle of a leaf window to open off the menu
  357.       OR pointer to a wimp menu structure to open with Zap data at
  358.       negative offsets (see E-Menu).
  359.  
  360. For example the command 'Save' opens the 'Save dialogue box' and returns the
  361. window handle of it. This is compatible with the normal action of the Same
  362. command when executed which is to open the box.
  363.  
  364. If bit 16 is clear and your command is used as a submenu then instead a
  365. writable icon is produced and the contents sent to the command when the user
  366. clicks on it. See bit 17.
  367.  
  368. Bit 17
  369. ------
  370.  
  371. This bit is only used when the command is used as a submenu pointer in the
  372. 'menus' file and bit 16 is clear. In this case a writable menu icon is
  373. provided for the user to type in the command argument. It this bit is set
  374. then you are asked to provided (1) a title for the menu containing the
  375. writable icon (2) a default string to place in the icon when the menu is
  376. created (usually a default value) (3) the size of the buffer in the writable
  377. icon. You are called with R2=17 and
  378.  
  379.  R0=0 => Return R0 as a pointer to the title string to use for the menu
  380.       (a maximum of 12 characters long and zero terminated).
  381.  R0=1 => If your command is of type 3 (string) then:
  382.       Return R0 as a pointer to the string to insert in the buffer
  383.         OR 0 to clear the buffer
  384.         OR -1 to leave the buffer as it currently is.
  385.         OR bit 31 set and +ve integer to insert in b0-b30
  386.      If your command is of type 1/2 (byte/word) then:
  387.       Return R0 as a pointer to the number to insert in the buffer
  388.        OR 0 to clear the buffer
  389.        OR -1 to leave the buffer unaltered.
  390.       Set b31 of R0 if you want the number inserted in hex.
  391.  R0=2 => Return R0 as the size in characters the buffer should be.
  392.  R0>2 => Ignore - I may add further reason codes in future.
  393.  
  394. If bit 17 is clear then this call is handled for you and the default values
  395. used are:
  396.  
  397.  (1) The title string is set to the name of the command as appearing in the
  398.      menus file.
  399.  (2) Buffer is left unchanged when the menu is updated.
  400.  (3) Buffer is made 16 characters wide if command takes a string argument
  401.      or 8 if it takes a numerical argument. 
  402.  
  403. Bit 18
  404. ------
  405.  
  406. This is only used when the command is used on a menu. If set then you are
  407. called to provide replacement text for the menu entry, overwriting what is
  408. already in the buffer. The number of characters in the menu entry text
  409. defines the size of the buffer reserved for the string. This is called
  410. whenever the menu is opened so the menu can change dynamically. You are
  411. called with:
  412.  
  413.  R0=pointer to command data (byte/word/string)
  414.  R2=18
  415.  
  416. and should return
  417.  
  418.  R0=pointer to text for the menu item (which may be clipped by Zap if it
  419.     doesn't fit in the buffer) / 0 if none (menu left as it is).
  420.  
  421. Bit 19
  422. ------
  423.  
  424. This is only used when the command is used on a menu. If set then you are
  425. called to provide a submenu to appear off this command. This is called every
  426. time the menu is opened, but not called if an alternative submenu is
  427. provided in the Menus file. You are called with:
  428.  
  429.  R0=pointer to command data (byte/word/string)
  430.  R2=19
  431.  
  432. and should return
  433.  
  434.  R0=pointer to submenu (in Zap-Wimp format) or 0 for none.
  435.  
  436. Bit 20
  437. ------
  438.  
  439. This is only used when the command is used on a menu. If set then you are
  440. asked whether the menu item should be omitted from the menu (for example the
  441. mode it accesses doesn't exist). This is called whenever the menu is opened
  442. so the menu entry can appear and disappear dynamically. It doubles memory
  443. used by the menu so don't use if unnecessary. You are called with:
  444.  
  445.  R0=pointer to command data (byte/word/string)
  446.  R2=20
  447.  
  448. and should return
  449.  
  450.  R0=b0 set to remove the menu item
  451.     b1-31 reserved (set to 0)
  452.  
  453. Bit 21-31
  454. ---------
  455.  
  456. Reserved - must be 0.
  457.  
  458. ************
  459. * EXAMPLE  *
  460. ************
  461.  
  462. The code below implements a simple command which asks you to enter a number
  463. into the minibuffer and then switches to that display mode. FNcall is a macro
  464. which calls the named Zap entry point (see E-Zapcalls for its definition).
  465.  
  466.     EQUD (3<<3)+(1<<6)        \ string argument + ask for prompt
  467.     .command_start
  468.     STMFD R13!,{R14}
  469.     TEQ R2,#6            \ is the minibuffer about to open
  470.     BEQ add_prompt
  471.     FNcall(Zap_MiniEval)        \ find the number typed
  472.     LDMVSFD R13!,{PC}        \ error
  473.     LDMCSFD R13!,{PC}        \ wasn't a valid number
  474.     FNcall(Zap_NewMode)        \ change mode
  475.     LDMFD R13!,{PC}            \ finished
  476.     .add_prompt
  477.     ADR R0,prompt_string
  478.     FNcall(Zap_MiniPrompt)        \ insert the prompt string
  479.     LDMFD R13!,{PC}         
  480.     .prompt_string
  481.     EQUS "New mode: "+CHR$0
  482.     ALIGN
  483.  
  484. It is the offset of command_start that you must place in your command table,
  485. not the offset of the EQUD flags word before it. Note that the command
  486. performs the same action regardless of whether R2=0 or R2=1.
  487.  
  488. *********************
  489. * Zap service calls *
  490. *********************
  491.  
  492. If the second word in your command table is non zero then it gives the
  493. module offset of a 'Zap service call handler'. This code is called at
  494. various points to tell you about things. In general the entry/exit
  495. conditions are:
  496.  
  497.     \E    R1=reason code and other registers may hold data.
  498.         R11=undefined
  499.         R12=Zaps workspace pointer as usual.
  500.     \X    You should preserve R1-R13 unless otherwise stated.
  501.         R0 and flags may be corrupted.
  502.         
  503. The (current) service calls are listed below. You should ignore unrecognised
  504. values in R1 so I can add more if necessary.
  505.  
  506. R1=0
  507. Zap is quitting and about to kill your module. Return R0=-1 to stop it.
  508. Your module will NOT be automatically killed if have no service call handler
  509. (for backwards compatibility).
  510.  
  511. R1=1
  512. Zap is just about to start up your command table.
  513.  
  514. R1=2
  515. Zap has started up your command table. You should use this call to claim any
  516. workspace via Zap_Claim. (This is usually called directly after R1=1).
  517.  
  518. R1=3
  519. Zap is deleting a file. R9=file block of file being deleted. (See E-File)
  520.  
  521. R1=4
  522. Zap is deleting a window. R8=window block of window being deleted.
  523. (See E-Windows)
  524.  
  525. R1>=&8000
  526. Zap has received an unrecognised wimp message that you may want to act on.
  527. The message is broadcast to all modes and command tables. Please IGNORE (ie
  528. return) unless you understand the message number and the window handle!! Use
  529. this to enable moving (via Wimp_OpenWindow) of your own windows!
  530.     \E R1=message block pointer (as sent by wimp)
  531.        R2=R1!16=message number if R3=17 or 19
  532.        R3=message type
  533.           (Null requests are scheduled - use Zap_CallBack)
  534.           1=redraw window request for unrecognised window
  535.           2=open window request for unrecognised window
  536.           3=close window request for unrecognised window
  537.           4=pointer leaving unrecognised window
  538.           5=pointer entering unrecognised window
  539.           6=mouse click on unrecognised window
  540.           (Drags dealt with by Zap - use Zap_DragBox)
  541.           8=key press for unrecognised window
  542.           (Menu clicks handled automatically - use Zap_OpenMenu)
  543.           10=scroll request for unrecognised window
  544.           11=lose caret for unrecognised window
  545.           12=gain caret for unrecognised window
  546.           13-16=passed straight on (not recognised by Zap)
  547.           17=unrecognised user message (or recognised message applying
  548.              to unrecognised window)
  549.           (type 18 gets passed on as 17 as well)
  550.           19=unrecognised bounced message
  551.           20+=passed straight on (not recognised by Zap)
  552.